package com.xjggb.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class HelloController {

    @GetMapping("/testA")
    public String show(){

       // try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
        return "-----------testA";
    }

    @GetMapping("/testB")
    public String show1(){
        log.info(Thread.currentThread().getName()+"\t"+".....testB");
        return "-----------testB";
    }



    @GetMapping("/testD")
    public String show2(){

       // try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); }

        log.info("test 测试RT");

        int i=10/0;

        return "---------------- testD ";
    }



    @GetMapping("/testE")
    public String show3(){

        log.info("test 测试异常数");
        int i=10/0;

        return "---------------- testE ";
    }


    //热点key

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotKey") //vale和blockHandler：没有斜杠，名字唯一
    public String show4(@RequestParam(value = "p1",required = false) String p1,
                        @RequestParam(value = "p2",required = false) String p2){

        return "-------> testHotKey ";
    }

    public String deal_testHotKey(String p1, String p2, BlockException blockException){
        return "-------> testHotKey o(╥﹏╥)o";
    }



}
